
function WebEntitySelector(id)
{
    this.superClase = WebSelector;
    this.superClase(id);
          
    this.entityName = "";
    this.foreingProperty = "";
    this.parentValue = "";
    
    // Funciones Publicas
	this.clone = EntitySelector_Clone;    
	
	// Funciones Protected
	this.evalOnSelect = EntitySelector_EvalOnSelect;    
	this.evalOnUnselect = EntitySelector_EvalOnUnselect;    	
}

function EntitySelector_Clone(newId)
{
    var newSelector = new WebEntitySelector(newId);

	newSelector.width = this.width;
	newSelector.size = this.size;
	newSelector.getListFunction = this.getListFunction;
	newSelector.length = this.length;
	newSelector.cssClass = this.cssClass;
	newSelector.enabled = this.enabled;
	newSelector.active = this.active;

	newSelector.onSelect = this.onSelect;	
	newSelector.onUnselect = this.onUnselect;	
	
	newSelector.entityName = this.entityName;
    newSelector.foreingProperty = this.foreingProperty;
    newSelector.parentValue = this.parentValue;
	    
    return newSelector;
}

function EntitySelector_RegisterRelationship(idparent, idchild)
{
    Entity_Relationships[idparent] = idchild;
}

function EntitySelector_EvalOnSelect(obj)
{
    if(typeof(Relationship_EvalOnChange) != "undefined")
        Relationship_EvalOnChange(this.id, this.getValue());

    eval(this.onSelect);
}

function EntitySelector_EvalOnUnselect()
{
    if(typeof(Relationship_EvalOnChange) != "undefined")
        Relationship_EvalOnChange(this.id, this.getValue());
        
    eval(this.onUnselect);
}

function EntitySelector_GetList(selectorId, value, maxtam)
{
    var mselector = Selector_Instances[selectorId];
    
    if(mselector.foreingProperty)
        EntitySelector.GetFilteredList(mselector.entityName, value, maxtam, mselector.foreingProperty, mselector.parentValue, EntitySelector_GetListCallBack, {id:selectorId, value:value});
    else
        EntitySelector.GetList(mselector.entityName, value, maxtam, EntitySelector_GetListCallBack, {id:selectorId, value:value});
}
    	
function EntitySelector_GetListCallBack(response)
{
    if ( (response.error) && (typeof(response.error) != "xml") ) {
        alert(response.error);
    }
    else {
        var doc = response.request.responseXML;
        var selectorId = response.context.id;
        var value = response.context.value;
        var selector = Selector_Get(selectorId);
        
        if(selector.getDescription() == value) {
            Selector_Fill(selectorId, doc);
        }
    }
}    